<template>
	<view class="page bg-background bg-yellow flex solid-bottom padding justify-center">
		<view class="padding flex-win">
			<view class="flex">
				<view class="flex-sub padding-lg text-center">
					<text class="text-green cuIcon-roundcheck text-lg" style="font-size: 36rpx;" v-if="(score >= scoreline)">本轮评分通过</text>
					<text class="text-red cuIcon-roundclose text-lg" style="font-size: 36rpx;" v-else>本轮评分未通过</text>
				</view>
			</view>
			<view class="flex margin-top">
				<view class="flex-sub text-center text-bold text-lg text-green">
					<image mode="widthFix" src="../static/image/success.png" style="width: 60%;" v-if="(score >= scoreline)"></image>
					<image mode="widthFix" src="../static/image/fail.png" style="width: 60%;" v-else></image>
				</view>
			</view>
			<view class="flex align-center">
				<view class="flex-sub text-center text-bold text-xxl text-white text-light" style="font-size: 70rpx;">得分</view>
			</view>
			<view class="flex">
				<view class="flex-sub text-center text-bold text-xsl text-white">{{score}}</view>
			</view>
			<view class="flex margin-top">
				<view class="flex-sub text-center text-xs text-mauve" v-if="(score >= scoreline)">
					<text>本轮奖励已发送至你的账户,请返回查看!</text>
				</view>
				<view class="flex-sub text-center text text-blue" v-else>
					<text>本轮不满{{scoreline}}评分,未能获得奖励!</text>
				</view>
			</view>
			<view class="flex margin-top margin-top-xl">
				<view class="flex-sub text-center">
					<button class="cu-btn round lg shadow-blur bg-green text-bold" @tap="onStart" style="width: 100%;">
						<view class="cuIcon-refresh" style="font-weight: 800;font-size: 40rpx;">再来一次</view>
					</button>
				</view>
			</view>
			<view class="flex margin-top">
				<view class="flex-sub text-left">
					<button class="cu-btn round lg shadow-blur bg-yellow" @tap="onBackIndex">
						<view class="iconfont icon-fanhui">返回账户</view>
					</button>
				</view>
				<view class="flex-sub text-right">
					<button class="cu-btn round lg shadow-blur bg-yellow" @tap="onUserShare" open-type="share">
						<view class="iconfont icon-fenxiangbeifen">炫耀一下</view>
					</button>
				</view>
			</view>
		</view>
		
		<view class="cu-modal show" @tap="RewardModel = false" v-if="RewardModel && (score >= scoreline)">
			<view class="cu-dialog hb-backgroud">
				<view class="cu-bar justify-end padding-bottom-xdl">
					<view class="action" @tap="RewardModel = false">
						<text class="cuIcon-close text-red"></text>
					</view>
				</view>
				<view class="padding-xl text-center margin-left-xl reward-font text-white">
					{{score * 0.001}}<text class="text-sm margin-left-xs">元</text>
				</view>
			</view>
		</view>
		
		<model-userlogin :isShow="Http.isLogin"></model-userlogin>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				score: 0,
				scoreline: 60,
				RewardModel: true,
				
				UserInfo: {
					wxUnionid: false,
					userName: null,
					shareCode: "R000000",
					usableMoney: "0.00",
					usableRbi: "0.00",
					castMoney: "0.00",
				},
			}
		},
		
		onLoad: function (options) {
			let _this = this;
			uni.$on("loginModel", (e)=>{
				_this.Http.isLogin = 'CLOSE';
				if('CLOSE' == e) {
					_this.getUserInfo();
				}
			});
			
			_this.score = options.score;
			
			// 通过音效
			if(_this.score >= _this.scoreline) {
				_this.Util.successAudio();
			}
			// 失败音效
			else {
				_this.Util.failAudio();
			}
		},
		
		methods: {
			onBackIndex() {
				uni.reLaunch({
					url: 'index'
				})
			},
			
			// 用户信息
			getUserInfo() {
				let _this = this;
				console.log("加载用户信息");
				
				// 发起请求
				_this.Http.post("my/user/info", {}, function(responseData) {
					console.log("用户信息", responseData);
					_this.UserInfo = responseData.returndata;
				});
			},
			
			onUserShare() {
				uni.share({
					provider: "weixin",
					scene: "WXSenceTimeline",
					type: 5,
					success: function(res) { },
					fail: function(err) { }
				});
			},
			
			// 开始答题
			onStart() {
				let _this = this;
				
				_this.Http.post("my/user/info", {}, function(responseData) {
					if(responseData.returndata && responseData.returndata.userName) {
						uni.navigateTo({
							url: 'tiku/puzzle'
						})
					}
				});
			},
		}
	}
</script>

<style>
	body, page, .page {
		background-color: #ffffff;
		min-height: 100vh;
	}

	.iconfont {
		font-weight: 800;
	}
	
	.bg-background {
		background-image:url('http://pic.51yuansu.com/backgd/cover/00/48/58/5c05f174048ee.jpg!/fw/780/quality/90/unsharp/true/compress/true');
		background-repeat:repeat-x;
		background-size: cover;
		background-position: center;
	}
	
	.flex-win {
		background-image:url("");
		margin: 200rpx auto;
		width: 80vw;
		height: 55vh;
		border-radius: 20rpx;
	}
	
	.cu-dialog {
	}
	
	.reward-font {
		font-size: 60rpx;
	}

</style>
